package servlet;

import com.alibaba.fastjson.JSON;
import entity.PageResult;
import entity.R;
import entity.classes;
import entity.student;
import org.apache.commons.lang3.StringUtils;
import org.junit.internal.Classes;
import service.ClassesService;
import service.StudentService;
import service.impl.ClassesServiceImpl;
import service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/classes")
public class ClassesServlet extends HttpServlet {
    private ClassesService classesService;

    @Override
    public void init() throws ServletException {
        classesService =new ClassesServiceImpl();
    }

    @Override
    public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置响应内容及字符集编码
        resp.setContentType("text/html;charset=utf8");
        //查询所有班级列表
        List<classes> classes= classesService.findALL();
        //转化为字符串
        R r = R.ok().put("list", classes);
        //打印输出
        resp.getWriter().println(JSON.toJSONString(r));
        resp.getWriter().flush();
    }



}
